/**
 @date 2020-07-21

 @version v1.0
---file comments----
*/

/****************************************************************************
 *
 * Header files
 *
 *****************************************************************************/
#include "ctc_cli.h"
#include "ctc_cli_common.h"
#include "ctcs_api.h"
#include "ctc_qos_cli.h"
#include "ctc_diag_cli.h"


#define CTC_CLI_QOS_QUEUE_ID_STR  "(port GPHYPORT_ID) (queue-id QUEUE_ID|)"
#define CTC_CLI_QOS_QUEUE_ID_DSCP  \
        CTC_CLI_GPORT_DESC,\
        CTC_CLI_GPHYPORT_ID_DESC,\
        CTC_CLI_QOS_QUEUE_STR,\
        CTC_CLI_QOS_QUEUE_VAL

#define CTC_QUEUE_NUM_PER_PORT 8

int32  _ctc_cli_asw_qos_queue_id_parser(ctc_vti_t* vty, ctc_qos_queue_id_t *p_queue, char** argv, uint16 argc)
{
    uint16 gport = 0;
    uint16  qid = 0;
    uint8 index = 0;
    uint8 queue_type = CTC_QUEUE_TYPE_NETWORK_EGRESS;
    int32 ret = CLI_SUCCESS;

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        /* port */
        CTC_CLI_GET_UINT16("gport", gport, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-id");
    if (0xFF != index)
    {
        /* queue-id */
        CTC_CLI_GET_UINT16("queue-id", qid, argv[index+1]);
    }

    p_queue->queue_type = queue_type;
    p_queue->gport      = gport;
    p_queue->queue_id   = qid;

    return ret;

}

CTC_CLI(ctc_cli_asw_qos_set_igs_domain_map,
        ctc_cli_asw_qos_set_igs_domain_map_cmd,
        "qos (domain DOMAIN) map (cos COS (dei DEI |)| dscp DSCP ) \
        to (priority PRIORITY) (color (green |yellow | red))",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_DOMAIN_STR,
        CTC_CLI_QOS_DOMAIN_VALUE,
        "Mapping",
        "Cos",
        "<0-7>",
        "Dei",
        "<0-1>",
        "Dscp",
        "<0-63>",
        "To",
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Color",
        "Green",
        "Yellow",
        "Red")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_domain_map_t domain_map;
    uint16 index = 0;
    sal_memset(&domain_map, 0, sizeof(ctc_qos_domain_map_t));
    index = CTC_CLI_GET_ARGC_INDEX("domain");
    if (0xFF != index)
    {
        /* qos domain */
        CTC_CLI_GET_UINT8("qos domain", domain_map.domain_id, argv[index + 1]);
    }


    index = CTC_CLI_GET_ARGC_INDEX("cos");
    if (0xFF != index)
    {
        /* cos */
        CTC_CLI_GET_UINT8("cos", domain_map.hdr_pri.dot1p.cos, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_IGS_COS_TO_PRI_COLOR;

        index = CTC_CLI_GET_ARGC_INDEX("dei");
        if (0xFF != index)
        {
            /* dei */
            CTC_CLI_GET_UINT8("dei", domain_map.hdr_pri.dot1p.dei, argv[index + 1]);
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("dscp");
    if (0xFF != index)
    {
        /* dscp */
        CTC_CLI_GET_UINT8("dscp", domain_map.hdr_pri.tos.dscp, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_IGS_DSCP_TO_PRI_COLOR;
    }

    /* priority */
    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        /* priority */
        CTC_CLI_GET_UINT8("priority", domain_map.priority, argv[index + 1]);
    }


    /* color */
    index = CTC_CLI_GET_ARGC_INDEX("green");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_GREEN;
    }

    index = CTC_CLI_GET_ARGC_INDEX("yellow");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_YELLOW;
    }

    index = CTC_CLI_GET_ARGC_INDEX("red");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_RED;
    }
    ret = ctcs_qos_set_domain_map(g_api_lchip, &domain_map);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_set_egs_domain_map,
        ctc_cli_asw_qos_set_egs_domain_map_cmd,
        "qos (domain DOMAIN) map (priority PRIORITY) (color (green | yellow | red)) to \
        (cos COS (dei DEI |)| dscp DSCP )",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_DOMAIN_STR,
        CTC_CLI_QOS_DOMAIN_VALUE,
        "Mapping",
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Color",
        "Green",
        "Yellow",
        "Red",
        "To",
        "Cos",
        "<0-7>",
        "Dei",
        "<0-1>",
        "Dscp",
        "<0-63>"
        )
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_domain_map_t domain_map;
    uint16 index = 0;

    sal_memset(&domain_map, 0, sizeof(ctc_qos_domain_map_t));

    index = CTC_CLI_GET_ARGC_INDEX("domain");
    if (0xFF != index)
    {
        /* qos domain */
        CTC_CLI_GET_UINT8("qos domain", domain_map.domain_id, argv[index + 1]);
    }

    /* priority */
    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("priority", domain_map.priority, argv[index + 1]);
    }


    /* color */
    index = CTC_CLI_GET_ARGC_INDEX("green");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_GREEN;
    }

    index = CTC_CLI_GET_ARGC_INDEX("yellow");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_YELLOW;
    }

    index = CTC_CLI_GET_ARGC_INDEX("red");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_RED;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cos");
    if (0xFF != index)
    {
        /* cos */
        CTC_CLI_GET_UINT8("cos", domain_map.hdr_pri.dot1p.cos, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_COS;

        index = CTC_CLI_GET_ARGC_INDEX("dei");
        if (0xFF != index)
        {
            /* dei */
            CTC_CLI_GET_UINT8("dei", domain_map.hdr_pri.dot1p.dei, argv[index + 1]);
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("dscp");
    if (0xFF != index)
    {
        /* dscp */
        CTC_CLI_GET_UINT8("dscp", domain_map.hdr_pri.tos.dscp, argv[index + 1]);
        domain_map.type = CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_DSCP;
    }
    ret = ctcs_qos_set_domain_map(g_api_lchip, &domain_map);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_show_qos_domain,
        ctc_cli_asw_qos_show_qos_domain_cmd,
        "show qos (domain DOAMIN) type (cos-map-pri(cos COS_VALUE (dei DEI|)) \
        |dscp-map-pri(dscp DSCP_VAlUE )|pri-map-cos(priority PRI_VALUE color (green | yellow | red)) \
        |pri-map-dscp(priority PRI_VALUE color (green | yellow | red)))",
        "Show",
        CTC_CLI_QOS_STR,
        "QoS domain",
        CTC_CLI_QOS_DOMAIN_VALUE,
        "Maping type",
        "Cos map to priority color",
        "Cos",
        "Cos vaule",
        "Dei",
        "Dei vaule",
        "Dscp map to priority color",
        "Dscp",
        "Dscp value",
        "Priority color map to cos",
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Color",
        "Green",
        "Yellow",
        "Red",
        "Priority color map to dscp",
        "Priority",
        CTC_CLI_PRIORITY_VALUE,
        "Color",
        "Green",
        "Yellow",
        "Red")
{
    int32 ret = CLI_SUCCESS;
    uint8 type = 0;
    uint8 index = 0;
    ctc_qos_domain_map_t domain_map;

    sal_memset(&domain_map, 0, sizeof(ctc_qos_domain_map_t));

    index = CTC_CLI_GET_ARGC_INDEX("domain");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("qos domain", domain_map.domain_id, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("cos-map-pri");
    if (0xFF != index)
    {
        type = CTC_QOS_DOMAIN_MAP_IGS_COS_TO_PRI_COLOR;
    }
    index = CTC_CLI_GET_ARGC_INDEX("dscp-map-pri");
    if (0xFF != index)
    {
        type = CTC_QOS_DOMAIN_MAP_IGS_DSCP_TO_PRI_COLOR;
    }
    index = CTC_CLI_GET_ARGC_INDEX("pri-map-cos");
    if (0xFF != index)
    {
        type = CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_COS;
    }
    index = CTC_CLI_GET_ARGC_INDEX("pri-map-dscp");
    if (0xFF != index)
    {
        type = CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_DSCP;
    }
    domain_map.type = type;
    index = CTC_CLI_GET_ARGC_INDEX("cos");
    if (0xFF != index)
    {
        /* cos */
        CTC_CLI_GET_UINT8("cos", domain_map.hdr_pri.dot1p.cos, argv[index + 1]);

        index = CTC_CLI_GET_ARGC_INDEX("dei");
        if (0xFF != index)
        {
            /* dei */
            CTC_CLI_GET_UINT8("dei", domain_map.hdr_pri.dot1p.dei, argv[index + 1]);
        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("dscp");
    if (0xFF != index)
    {
        /* dscp */
        CTC_CLI_GET_UINT8("dscp", domain_map.hdr_pri.tos.dscp, argv[index + 1]);
    }
     /* priority */
    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        /* priority */
        CTC_CLI_GET_UINT8("priority", domain_map.priority, argv[index + 1]);
    }


    /* color */
    index = CTC_CLI_GET_ARGC_INDEX("green");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_GREEN;
    }

    index = CTC_CLI_GET_ARGC_INDEX("yellow");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_YELLOW;
    }

    index = CTC_CLI_GET_ARGC_INDEX("red");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_RED;
    }
    /* priority */
    index = CTC_CLI_GET_ARGC_INDEX("priority");
    if (0xFF != index)
    {
        /* priority */
        CTC_CLI_GET_UINT8("priority", domain_map.priority, argv[index + 1]);
    }


    /* color */
    index = CTC_CLI_GET_ARGC_INDEX("green");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_GREEN;
    }

    index = CTC_CLI_GET_ARGC_INDEX("yellow");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_YELLOW;
    }

    index = CTC_CLI_GET_ARGC_INDEX("red");
    if (0xFF != index)
    {
        domain_map.color = CTC_QOS_COLOR_RED;
    }

    ret = ctcs_qos_get_domain_map(g_api_lchip, &domain_map);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    switch (type)
    {
         case CTC_QOS_DOMAIN_MAP_IGS_COS_TO_PRI_COLOR:
            {
                 ctc_cli_out("ingress cos + dei -> priority + color mapping table\n");
                 ctc_cli_out("-----------------------------------------------------\n");
                 ctc_cli_out("   cos(%d)  +  dei(%d) -> priority(%d)  + color(%d)\n",
                            domain_map.hdr_pri.dot1p.cos, domain_map.hdr_pri.dot1p.dei, domain_map.priority, domain_map.color);
            }
            break;

         case CTC_QOS_DOMAIN_MAP_IGS_DSCP_TO_PRI_COLOR:
            {
                ctc_cli_out("ingress dscp  -> priority + color mapping table\n");
                ctc_cli_out("-----------------------------------------------------\n");
                ctc_cli_out("    dscp(%d)  -> priority(%d)  + color(%d)\n",
                            domain_map.hdr_pri.tos.dscp, domain_map.priority, domain_map.color);
            }
            break;

         case CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_COS:
            {
                ctc_cli_out("egress  priority + color -> cos  mapping table\n");
                ctc_cli_out("-----------------------------------------------------\n");
                ctc_cli_out(" priority(%d)  + color(%d)  -> cos(%d) + dei(%d)\n",
                              domain_map.priority, domain_map.color, domain_map.hdr_pri.dot1p.cos, domain_map.hdr_pri.dot1p.dei);
            }
            break;

         case CTC_QOS_DOMAIN_MAP_EGS_PRI_COLOR_TO_DSCP:
            {
                ctc_cli_out("egress  priority + color -> dscp  mapping table\n");
                ctc_cli_out("-----------------------------------------------------\n");
                ctc_cli_out(" priority(%d)  + color(%d)  -> dscp(%d)\n",
                              domain_map.priority, domain_map.color, domain_map.hdr_pri.tos.dscp);
            }
            break;
    }
    return ret;
}

CTC_CLI(ctc_cli_asw_qos_create_policer,
        ctc_cli_asw_qos_create_policer_cmd,
        "qos policer attach (port GPORT (in|out) |flow POLICER_ID(in|out)) \
         (mode (rfc2697|rfc2698|rfc4115|bwp|stbm)) ((color-blind|color-aware)|)  (stats-en|) (stats-mode MODE|)\
          (cir CIR) (cbs CBS |) ((pir PIR|eir EIR)|) ((pbs PBS|ebs EBS)|)(drop-color (none|red|yellow)|) \
        ",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Attach policer",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Ingress direction",
        "Egress direction",
        CTC_CLI_QOS_FLOW_PLC_STR,
        "QoS flow policer index",
        "Ingress direction",
        "Egress direction",
        "Policer mode",
        "RFC2697",
        "RFC2698",
        "RFC4115, enhaned ",
        "MEF 10.1,bandwidth profile",
        "STBM, Single Token Bucket Meter",
        "Color blind mode, default policing mode",
        "Color aware mode",
        "Stats enable",
        "Stats mode",
        "Mode Value",
        CTC_CLI_QOS_PLC_CIR_STR,
        CTC_CLI_QOS_PLC_CIR_VAL,
        CTC_CLI_QOS_PLC_CBS_STR,
        CTC_CLI_QOS_PLC_CBS_VAL,
        CTC_CLI_QOS_PLC_PIR_STR,
        CTC_CLI_QOS_PLC_PIR_VAL,
        CTC_CLI_QOS_PLC_EIR_STR,
        CTC_CLI_QOS_PLC_EIR_VAL,
        CTC_CLI_QOS_PLC_PBS_STR,
        CTC_CLI_QOS_PLC_PBS_VAL,
        CTC_CLI_QOS_PLC_EBS_STR,
        CTC_CLI_QOS_PLC_EBS_VAL,
        "Drop color config",
        "None",
        "Red",
        "Yellow"
        )
{
    ctc_qos_policer_t policer_param;
    uint32 gport = 0;
    int16 idx = 0;
    uint8 dir = 0;
    int32 ret = CLI_SUCCESS;

    sal_memset(&policer_param, 0, sizeof(ctc_qos_policer_t));

    policer_param.dir = CTC_INGRESS;
    policer_param.enable = 1;
    policer_param.policer.is_color_aware = 0;
    policer_param.policer.cbs = 0x7D8;
    policer_param.policer.pbs = 0x7D8;
    policer_param.policer.drop_color = CTC_QOS_COLOR_RED;
    idx = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("port", gport, argv[idx + 1]);
        policer_param.id.gport = gport;
        policer_param.type = CTC_QOS_POLICER_TYPE_PORT;
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        policer_param.dir = dir;
    }
    idx = CTC_CLI_GET_ARGC_INDEX("flow");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_FLOW;
    }
    idx = CTC_CLI_GET_ARGC_INDEX("mode");
    if (0xFF != idx)
    {
        if (CLI_CLI_STR_EQUAL("rfc2697", idx + 1))
        {
            policer_param.policer.policer_mode = CTC_QOS_POLICER_MODE_RFC2697;
        }
        else if(CLI_CLI_STR_EQUAL("rfc2698", idx + 1))
        {
            policer_param.policer.policer_mode = CTC_QOS_POLICER_MODE_RFC2698;
        }
        else if(CLI_CLI_STR_EQUAL("rfc4115", idx + 1))
        {
            policer_param.policer.policer_mode = CTC_QOS_POLICER_MODE_RFC4115;
        }
        else if(CLI_CLI_STR_EQUAL("bwp", idx + 1))
        {
            policer_param.policer.policer_mode = CTC_QOS_POLICER_MODE_MEF_BWP;
        }
        else if(CLI_CLI_STR_EQUAL("stbm", idx + 1))
        {
            policer_param.policer.policer_mode = CTC_QOS_POLICER_MODE_STBM;
        }
    }
    idx = CTC_CLI_GET_ARGC_INDEX("color-blind");
    if (0xFF != idx)
    {
        policer_param.policer.is_color_aware = 0;
    }
    idx = CTC_CLI_GET_ARGC_INDEX("color-aware");
    if (0xFF != idx)
    {
        policer_param.policer.is_color_aware = 1;
    }
    idx = CTC_CLI_GET_ARGC_INDEX("cir");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("cir", policer_param.policer.cir, argv[idx + 1]);
    }
    idx = CTC_CLI_GET_ARGC_INDEX("cbs");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("cbs", policer_param.policer.cbs, argv[idx + 1]);
    }
    idx = CTC_CLI_GET_ARGC_INDEX("pir");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("pir", policer_param.policer.pir, argv[idx + 1]);
    }
    idx = CTC_CLI_GET_ARGC_INDEX("eir");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("eir", policer_param.policer.pir, argv[idx + 1]);
    }
    idx = CTC_CLI_GET_ARGC_INDEX("pbs");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("pbs", policer_param.policer.pbs, argv[idx + 1]);
    }
    idx = CTC_CLI_GET_ARGC_INDEX("ebs");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("ebs", policer_param.policer.pbs, argv[idx + 1]);
    }

    idx = CTC_CLI_GET_ARGC_INDEX("drop-color");
    if (0xFF != idx)
    {
        if (CLI_CLI_STR_EQUAL("red", idx + 1))
        {
            policer_param.policer.drop_color = CTC_QOS_COLOR_RED;
        }
        else if (CLI_CLI_STR_EQUAL("yel", idx + 1))
        {
            policer_param.policer.drop_color = CTC_QOS_COLOR_YELLOW;
        }
        else if (CLI_CLI_STR_EQUAL("none", idx + 1))
        {
            policer_param.policer.drop_color = CTC_QOS_COLOR_NONE;
        }
    }

   /* enable stats */
    idx = CTC_CLI_GET_ARGC_INDEX("stats-en");
    if (0xFF != idx)
    {
        policer_param.policer.stats_en = TRUE;
    }

    idx = CTC_CLI_GET_ARGC_INDEX("stats-mode");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("mode", policer_param.policer.stats_mode, argv[idx + 1]);
    }

    ret = ctcs_qos_set_policer(g_api_lchip, &policer_param);
    ctc_cli_out("%% policer id = %d \n",policer_param.id.policer_id);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_remove_policer,
        ctc_cli_asw_qos_remove_policer_cmd,
        "qos policer detach (port GPORT (in|out) |flow POLICER_ID(in|out))",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Detach policer",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Ingress direction",
        "Egress direction",
        CTC_CLI_QOS_FLOW_PLC_STR,
        "QoS flow policer index",
        "Ingress direction",
        "Egress direction"
        )
{
    int32 ret = CLI_SUCCESS;
    int16 idx = 0;
    uint8 dir = 0;
    uint32 gport = 0;
    ctc_qos_policer_t policer_param;

    sal_memset(&policer_param, 0, sizeof(ctc_qos_policer_t));

    policer_param.dir = CTC_INGRESS;
    policer_param.enable = 0;
    idx = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("port", gport, argv[idx + 1]);
        policer_param.id.gport = gport;
        policer_param.type = CTC_QOS_POLICER_TYPE_PORT;

        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }
        policer_param.dir = dir;
    }
    idx = CTC_CLI_GET_ARGC_INDEX("flow");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_FLOW;
    }
    ret = ctcs_qos_set_policer(g_api_lchip, &policer_param);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_show_policer,
        ctc_cli_asw_qos_show_policer_cmd,
        "show qos policer (port GPORT (in|out) |flow POLICER_ID(in|out))",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Ingress direction",
        "Egress direction",
        CTC_CLI_QOS_FLOW_PLC_STR,
        "QoS flow policer index",
        "Ingress direction",
        "Egress direction"
        )
{
    ctc_qos_policer_t policer_param;
    int32 ret = CLI_SUCCESS;
    int16 idx = 0;
    uint8 dir = 0;
    uint16 gport = 0;
    uint32 policer_id = 0;
    char policer_mode[5][32] = {"stbm","rfc2697", "rfc2698", "rfc4115", "bwp"};
    sal_memset(&policer_param, 0, sizeof(ctc_qos_policer_t));

    idx = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("port", gport, argv[idx + 1]);
        policer_param.id.gport = gport;
        policer_param.type = CTC_QOS_POLICER_TYPE_PORT;
        policer_id = gport;
        if (CLI_CLI_STR_EQUAL("in", idx + 2))
        {
            dir = CTC_INGRESS;
        }
        else
        {
            dir = CTC_EGRESS;
        }
        policer_param.dir = dir;
    }
    idx = CTC_CLI_GET_ARGC_INDEX("flow");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT16("policer id", policer_param.id.policer_id, argv[idx + 1]);
        policer_param.type = CTC_QOS_POLICER_TYPE_FLOW;
        policer_id = policer_param.id.policer_id;
    }

    ret = ctcs_qos_get_policer(g_api_lchip, &policer_param);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    if (policer_param.type == CTC_QOS_POLICER_TYPE_PORT)
    {
        ctc_cli_out("%-6s %-7s", "port",  "enable");
    }
    else if ((policer_param.type == CTC_QOS_POLICER_TYPE_FLOW))
    {
        ctc_cli_out( "%-6s %-7s", "plc-id","enable");
    }
    ctc_cli_out( "%-13s %-13s %-12s %-12s \n", "cir(kbps/pps)", "pir(kbps/pps)", "cbs(kb/pkt)", "pbs(kb/pkt)");
    ctc_cli_out("------------------------------------------------------------------\n");
    ctc_cli_out("0x%04x  %-7d ", policer_id, 1);
    ctc_cli_out("%-13d %-13d %-12d %-12d\n", policer_param.policer.cir, policer_param.policer.pir, policer_param.policer.cbs,
                policer_param.policer.pbs);
    ctc_cli_out("\nDetail information:\n");
    ctc_cli_out("----------------------------------------------------------\n");
    ctc_cli_out("%-11s %-11s %-11s %-4s \n","stats-mode","policer-mode","color-aware","drop-color");
    ctc_cli_out("----------------------------------------------------------\n");
    ctc_cli_out("%-11d %-11s %-11d %-4d\n",policer_param.policer.stats_mode, policer_mode[policer_param.policer.policer_mode],
                policer_param.policer.is_color_aware, policer_param.policer.drop_color);

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_get_ipgEn_status,
        ctc_cli_asw_qos_get_ipgEn_cmd,
        "show qos policer ipg",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Ipg used for policer"
        )
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_glb_cfg_t p_glb_cfg;

    sal_memset(&p_glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    p_glb_cfg.cfg_type = CTC_QOS_GLB_CFG_POLICER_IPG_EN;
    ret = ctcs_qos_get_global_config(g_api_lchip,&p_glb_cfg);
    ctc_cli_out("\nQos IPG status:%d\n", p_glb_cfg.u.value);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_set_ipgEn_status,
        ctc_cli_asw_qos_set_ipgEn_cmd,
        "qos policer (ipg) (enable | disable)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Ipg used for policer",
        "Globally enable ",
        "Globally disable")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_glb_cfg_t p_glb_cfg;

    sal_memset(&p_glb_cfg, 0, sizeof(ctc_qos_glb_cfg_t));
    p_glb_cfg.cfg_type = CTC_QOS_GLB_CFG_POLICER_IPG_EN;
    if (CLI_CLI_STR_EQUAL("e", 1))
    {
        p_glb_cfg.u.value = 0;
    }
    else
    {
        p_glb_cfg.u.value = 1;
    }
    ret = ctcs_qos_set_global_config(g_api_lchip,&p_glb_cfg);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d\n", ret);
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_set_resrc_flow_ctl,
        ctc_cli_asw_qos_set_resrc_flow_ctl_cmd,
        "qos resrc-mgr flow-ctl (port GPHYPORT_ID) (xon-thrd TRHD xoff-thrd THRD drop-thrd THRD)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Flow control",
        CTC_CLI_PORT_M_STR,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Xon thresthold",
        "Threshold",
        "Xoff thresthold",
        "Threshold",
        "Drop thresthold",
        "Threshold")
{
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;
    uint8 index =0;
    sal_memset(&resrc, 0, sizeof(resrc));
    resrc.cfg_type = CTC_QOS_RESRC_CFG_FLOW_CTL;

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("port", resrc.u.flow_ctl.gport, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("xon-thrd");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("xon-thrd", resrc.u.flow_ctl.xon_thrd, argv[index + 1]);
    }


    index = CTC_CLI_GET_ARGC_INDEX("xoff-thrd");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("xoff-thrd", resrc.u.flow_ctl.xoff_thrd, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("drop-thrd");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("drop-thrd", resrc.u.flow_ctl.drop_thrd, argv[index + 1]);
    }

    ret = ctcs_qos_set_resrc(g_api_lchip, &resrc);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_get_resrc_flow_ctl,
        ctc_cli_asw_qos_get_resrc_flow_ctl_cmd,
        "show qos resrc-mgr flow-ctl (port GPHYPORT_ID)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Flow control",
        CTC_CLI_PORT_M_STR,
        CTC_CLI_GPHYPORT_ID_DESC
        )
{
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;
    uint8 index =0;

    sal_memset(&resrc, 0, sizeof(resrc));
    resrc.cfg_type = CTC_QOS_RESRC_CFG_FLOW_CTL;

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("port", resrc.u.flow_ctl.gport, argv[index + 1]);
    }

    ret = ctcs_qos_get_resrc(g_api_lchip, &resrc);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("%-10s\n", "Flow-control information");
    ctc_cli_out("----------------\n");
    ctc_cli_out("%-19s : %-8u\n","Xon threshold", resrc.u.flow_ctl.xon_thrd);
    ctc_cli_out("%-19s : %-8u\n","Xoff threshold", resrc.u.flow_ctl.xoff_thrd);
    ctc_cli_out("%-19s : %-8u\n","Drop threshold", resrc.u.flow_ctl.drop_thrd);
    ctc_cli_out("----------------\n");

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_set_resrc_ingress,
        ctc_cli_asw_qos_set_resrc_ingress_cmd,
        "qos resrc-mgr ingress (port-min port GPHYPORT_ID threshold THRD)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Ingress",
        "Port minimum guarantee",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Threshold",
        "Threshold value")
{
    uint8  index = 0;
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;

    sal_memset(&resrc, 0, sizeof(resrc));

    index = CTC_CLI_GET_ARGC_INDEX("port-min");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16_RANGE("port", resrc.u.port_min.gport, argv[index + 2], 0, CTC_MAX_UINT16_VALUE);
        CTC_CLI_GET_UINT16_RANGE("threshold", resrc.u.port_min.threshold, argv[index + 4], 0, CTC_MAX_UINT16_VALUE);
        resrc.u.port_min.dir = CTC_INGRESS;
        resrc.cfg_type = CTC_QOS_RESRC_CFG_PORT_MIN;
    }

    ret = ctcs_qos_set_resrc(g_api_lchip, &resrc);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_set_resrc_egress,
        ctc_cli_asw_qos_set_resrc_egress_cmd,
        "qos resrc-mgr egress (port-min port GPHYPORT_ID threshold THRD)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Egress",
        "Port minimum guarantee",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Threshold",
        "Threshold value")
{
    uint8  index = 0;
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;

    sal_memset(&resrc, 0, sizeof(resrc));

    index = CTC_CLI_GET_ARGC_INDEX("port-min");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16_RANGE("port", resrc.u.port_min.gport, argv[index + 2], 0, CTC_MAX_UINT16_VALUE);
        CTC_CLI_GET_UINT16_RANGE("threshold", resrc.u.port_min.threshold, argv[index + 4], 0, CTC_MAX_UINT16_VALUE);
        resrc.u.port_min.dir = CTC_EGRESS;
        resrc.cfg_type = CTC_QOS_RESRC_CFG_PORT_MIN;
    }

    ret = ctcs_qos_set_resrc(g_api_lchip, &resrc);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_get_resrc,
        ctc_cli_asw_qos_get_resrc_cmd,
        "show qos resrc-mgr (ingress|egress) (port-min port GPHYPORT_ID threshold)",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Ingress",
        "Egress",
        "Port minimum guarantee",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Threshold")
{
    uint8  index = 0;
    ctc_qos_resrc_t resrc;
    int32 ret = CLI_SUCCESS;

    sal_memset(&resrc, 0, sizeof(resrc));
    index = CTC_CLI_GET_ARGC_INDEX("ingress");
    if (0xFF != index)
    {
        resrc.u.port_min.dir = CTC_INGRESS;
    }
    else
    {
        resrc.u.port_min.dir = CTC_EGRESS;
    }

    index = CTC_CLI_GET_ARGC_INDEX("port-min");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16_RANGE("port", resrc.u.port_min.gport, argv[index + 2], 0, CTC_MAX_UINT16_VALUE);
        resrc.cfg_type = CTC_QOS_RESRC_CFG_PORT_MIN;
    }

    ret = ctcs_qos_get_resrc(g_api_lchip, &resrc);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    if(resrc.cfg_type == CTC_QOS_RESRC_CFG_PORT_MIN)
    {
        ctc_cli_out("%-10s\n", "Port-min information");
        ctc_cli_out("----------------\n");
        ctc_cli_out("%-19s : %-8u\n",
                        "Threshold", resrc.u.port_min.threshold);
    }
    ctc_cli_out("----------------\n");

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_set_port_queue_shape,
        ctc_cli_asw_qos_set_port_queue_shape_cmd,
        "qos shape queue" CTC_CLI_QOS_QUEUE_ID_STR "(none | {cir CIR (cbs CBS|) | pir PIR (pbs PBS|)} (pps-en|))",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        "Queue shaping",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Cancel queue shaping",
        CTC_CLI_QOS_PLC_CIR_STR,
        CTC_CLI_QOS_PLC_CIR_VAL,
        CTC_CLI_QOS_PLC_CBS_STR,
        CTC_CLI_QOS_SHAPE_CBS_STR,
        CTC_CLI_QOS_PLC_PIR_STR,
        CTC_CLI_QOS_PLC_PIR_VAL,
        CTC_CLI_QOS_PLC_PBS_STR,
        CTC_CLI_QOS_SHAPE_PBS_STR,
        "PPS enable")
{
    int32 ret = CLI_SUCCESS;
    ctc_qos_shape_t qos_shape;
    ctc_qos_shape_queue_t shape;
    uint8 index = 0;

    sal_memset(&qos_shape, 0, sizeof(qos_shape));
    sal_memset(&shape, 0, sizeof(shape));

    _ctc_cli_asw_qos_queue_id_parser(vty, &shape.queue, &argv[0], argc);
    qos_shape.type = CTC_QOS_SHAPE_QUEUE;


    index = CTC_CLI_GET_ARGC_INDEX("none");
    if (0xFF != index)
    {
        shape.enable = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cir");
    if (0xFF != index)
    {
        /* cir */
        CTC_CLI_GET_UINT32("cir", shape.cir, argv[index + 1]);
        shape.enable = 1;
    }

    index = CTC_CLI_GET_ARGC_INDEX("cbs");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("cbs", shape.cbs, argv[index + 1]);
    }
    else
    {
        shape.cbs = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pir");
    if (0xFF != index)
    {
        /* cir */
        CTC_CLI_GET_UINT32("pir", shape.pir, argv[index + 1]);
        shape.enable = 1;
    }
    else
    {
        shape.pir = shape.cir;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pbs");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT32("pbs", shape.pbs, argv[index + 1]);
    }
    else
    {
        shape.pbs = 0;
    }

    index = CTC_CLI_GET_ARGC_INDEX("pps-en");
    if (0xFF != index)
    {
        shape.pps_en = 1;
    }

    sal_memcpy(&qos_shape.shape, &shape, sizeof(shape));
    ret = ctcs_qos_set_shape(g_api_lchip, &qos_shape);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_set_port_shape,
        ctc_cli_asw_qos_set_port_shape_cmd,
        "qos shape port GPHYPORT_ID (none | pir PIR (pbs PBS|) (pps-en|))",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Cancel port shaping",
        CTC_CLI_QOS_PLC_PIR_STR,
        CTC_CLI_QOS_PLC_PIR_VAL,
        CTC_CLI_QOS_PLC_PBS_STR,
        CTC_CLI_QOS_SHAPE_PBS_STR,
        "PPS enable"
        )
{
    uint32 gport = 0;
    uint8 index  = 0 ;
    int32 ret = CLI_SUCCESS;
    ctc_qos_shape_t qos_shape;
    ctc_qos_shape_port_t shape;

    sal_memset(&qos_shape, 0, sizeof(ctc_qos_shape_t));
    sal_memset(&shape, 0, sizeof(ctc_qos_shape_port_t));
    /* port */
    CTC_CLI_GET_UINT32("gport", gport, argv[0]);


    shape.gport = gport;
    qos_shape.type = CTC_QOS_SHAPE_PORT;

    if (CLI_CLI_STR_EQUAL("none", 1))
    {
        shape.enable = 0;
    }
    else
    {
        /* rate */
        CTC_CLI_GET_UINT32("rate", shape.pir, argv[2]);
        shape.pbs = 0;
        shape.enable = 1;

        index = CTC_CLI_GET_ARGC_INDEX("pbs");
        if (0xFF != index)
        {
            CTC_CLI_GET_UINT32("pbs", shape.pbs, argv[index+1]);
        }
        index = CTC_CLI_GET_ARGC_INDEX("pps-en");
        if (0xFF != index)
        {
            shape.pps_en = 1;
        }
    }

    sal_memcpy(&qos_shape.shape, &shape, sizeof(ctc_qos_shape_port_t));
    ret = ctcs_qos_set_shape(g_api_lchip, &qos_shape);


    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_show_shape,
        ctc_cli_asw_qos_show_shape_cmd,
        "show qos shape ((port GPHYPORT_ID)|((queue)" CTC_CLI_QOS_QUEUE_ID_STR"))",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SHAPE_STR,
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Queue shaping",
        CTC_CLI_QOS_QUEUE_ID_DSCP)
{
    int32 ret = CLI_SUCCESS;
    uint32 gport = 0;
    ctc_qos_shape_t qos_shape;
    uint8 index = 0;

    sal_memset(&qos_shape, 0, sizeof(qos_shape));

    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        /* port */
        CTC_CLI_GET_UINT32("gport", gport, argv[index+1]);
        qos_shape.type = CTC_QOS_SHAPE_PORT;
        qos_shape.shape.port_shape.gport = gport;
    }
    index = CTC_CLI_GET_ARGC_INDEX("queue");
    if (0xFF != index)
    {
        _ctc_cli_asw_qos_queue_id_parser(vty, &qos_shape.shape.queue_shape.queue, &argv[0], argc);
        qos_shape.type = CTC_QOS_SHAPE_QUEUE;
    }

    ret = ctcs_qos_get_shape(g_api_lchip, &qos_shape);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    if(qos_shape.type == CTC_QOS_SHAPE_QUEUE)
    {
        ctc_cli_out("\nQueue shape:\n");
        ctc_cli_out("%-10s %-15s %-15s %-15s %-15s\n","shp-en", "cir(kbps/pps)", "cbs(kb/pkt)","pir(kbps/pps)", "pbs(kb/pkt)");
        ctc_cli_out("-----------------------------------------------------------------\n");
        ctc_cli_out("%-10d %-15u %-15u %-15u %-15u\n",qos_shape.shape.queue_shape.enable,qos_shape.shape.queue_shape.cir,
                    qos_shape.shape.queue_shape.cbs, qos_shape.shape.queue_shape.pir, qos_shape.shape.queue_shape.pbs);
    }
    else if(qos_shape.type == CTC_QOS_SHAPE_PORT)
    {
        ctc_cli_out("\nPort shape:\n");
        ctc_cli_out("%-10s %-15s %-15s \n","shp-en","pir(kbps/pps)", "pbs(kb/pkt)");
        ctc_cli_out("-----------------------------------------------------------------\n");
        ctc_cli_out("%-10d %-15u %-15u \n",qos_shape.shape.port_shape.enable, qos_shape.shape.port_shape.pir, qos_shape.shape.port_shape.pbs);
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_set_port_queue_class,
        ctc_cli_asw_qos_set_port_queue_class_cmd,
        "qos schedule queue-class" CTC_CLI_QOS_QUEUE_ID_STR "(exceed-class ECDCLASS)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Queue class",
        CTC_CLI_QOS_QUEUE_ID_DSCP,
        "Exceed yellow class",
        CTC_CLI_QOS_CLASS_VAL)
{
    uint8 queue_class = 0;
    int32 ret = CLI_SUCCESS;
    uint16 index = 0;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));

    _ctc_cli_asw_qos_queue_id_parser(vty, &sched_param.sched.queue_sched.queue, &argv[0], argc);
    index = CTC_CLI_GET_ARGC_INDEX("exceed-class");
    if (0xFF != index)
    {
        sched_param.sched.queue_sched.cfg_type = CTC_QOS_SCHED_CFG_EXCEED_CLASS;
        CTC_CLI_GET_UINT8_RANGE("exceed class", queue_class, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        sched_param.sched.queue_sched.exceed_class = queue_class;
    }

    ret = ctcs_qos_set_sched(g_api_lchip, &sched_param);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_show_sched,
        ctc_cli_asw_qos_show_sched_cmd,
        "show qos schedule (queue)" CTC_CLI_QOS_QUEUE_ID_STR,
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Queue",
        CTC_CLI_QOS_QUEUE_ID_DSCP)
{
    int32 ret = CLI_SUCCESS;
    uint16 index = 0;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));
    _ctc_cli_asw_qos_queue_id_parser(vty, &sched_param.sched.queue_sched.queue, &argv[0], argc);
    index = CTC_CLI_GET_ARGC_INDEX("queue");
    if (0xFF != index)
    {
        sched_param.sched.queue_sched.cfg_type = CTC_QOS_SCHED_CFG_EXCEED_CLASS;
    }

    ret = ctcs_qos_get_sched(g_api_lchip, &sched_param);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("\nQueue Scheduler:\n");
    ctc_cli_out("-------------------------------\n");
    ctc_cli_out("%-30s: %d \n", "Queue Class", sched_param.sched.queue_sched.exceed_class);
    ctc_cli_out("%-30s: %d \n", "Weight", sched_param.sched.queue_sched.exceed_weight);

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_set_queue_wdrr_weight,
        ctc_cli_asw_qos_set_queue_wdrr_weight_cmd,
        "qos schedule queue-wdrr  (port GPHYPORT_ID)  (exceed-class) \
    (wdrr-weight WEIGHT WEIGHT WEIGHT WEIGHT WEIGHT WEIGHT WEIGHT WEIGHT |queue-id QUEUE_ID weight WEIGHT)",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_SCHED_STR,
        "Queue wdrr",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        "Exceed yellow class weight",
        "Config WDRR weight",
        "Weight of queue 0, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 1, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 2, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 3, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 4, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 5, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 6, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Weight of queue 7, "CTC_CLI_QOS_WDRR_WEIGHT_VAL,
        "Queue id",
        CTC_CLI_QOS_QUEUE_VAL,
        "Config WDRR weight",
        CTC_CLI_QOS_WDRR_WEIGHT_VAL)
{
    uint16 gport = 0;
    uint16 weight = 0;
    int8   qid = 0;
    int32  ret = 0;
    uint16 index = 0;
    ctc_qos_sched_t sched_param;

    sal_memset(&sched_param, 0, sizeof(ctc_qos_sched_t));
    sched_param.sched.queue_sched.queue.queue_type = CTC_QUEUE_TYPE_NETWORK_EGRESS;


    /* port */
    index = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("gport", gport, argv[index + 1]);
        sched_param.sched.queue_sched.queue.gport = gport;
    }

    index = CTC_CLI_GET_ARGC_INDEX("exceed-class");
    if (0xFF != index)
    {
        sched_param.sched.queue_sched.cfg_type = CTC_QOS_SCHED_CFG_EXCEED_WEIGHT;
    }

    index = CTC_CLI_GET_ARGC_INDEX("wdrr-weight");
    if (0xFF != index)
    {
        /* weight values */
        for (qid = 0; qid < CTC_QUEUE_NUM_PER_PORT; qid++)
        {
            CTC_CLI_GET_UINT16_RANGE("weight", weight, argv[qid + index + 1], 0, CTC_MAX_UINT16_VALUE);

            sched_param.sched.queue_sched.queue.queue_id = qid;
            sched_param.sched.queue_sched.exceed_weight = weight;

            ret = ctcs_qos_set_sched(g_api_lchip, &sched_param);

            if (ret < 0)
            {
                ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
                return CLI_ERROR;
            }

        }
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8_RANGE("queueId", qid, argv[index + 1], 0, CTC_MAX_UINT8_VALUE);
        CTC_CLI_GET_UINT16_RANGE("weight", weight, argv[index + 3], 0, CTC_MAX_UINT16_VALUE);

        sched_param.sched.queue_sched.queue.queue_id = qid;

        sched_param.sched.queue_sched.exceed_weight = weight;


        ret = ctcs_qos_set_sched(g_api_lchip, &sched_param);

        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }

    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_show_resrc_usage,
        ctc_cli_asw_qos_show_resrc_usage_cmd,
        "show qos resrc-mgr (pool-count|queue-count" CTC_CLI_QOS_QUEUE_ID_STR ")",
        "Show",
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_RESRC_STR,
        "Pool count",
        "Queue instant count",
        CTC_CLI_QOS_QUEUE_ID_DSCP)
{
    int32 ret = CLI_SUCCESS;
    uint8  index = 0;
    ctc_qos_resrc_pool_stats_t stats;

    sal_memset(&stats, 0, sizeof(stats));

    index = CTC_CLI_GET_ARGC_INDEX("pool-count");
    if (0xFF != index)
    {
        ctc_cli_out("%-10s\n", "Ingress pool");
        ctc_cli_out("----------------\n");
        stats.type = CTC_QOS_RESRC_STATS_IGS_TOTAL_COUNT;
        ret = ctcs_qos_query_pool_stats(g_api_lchip, &stats);
        ctc_cli_out("%-5s : %5u\n", "Total", stats.count);
        ctc_cli_out("\n");
        ctc_cli_out("%-5s\n", "Egress pool");
        ctc_cli_out("----------------\n");
        stats.type = CTC_QOS_RESRC_STATS_EGS_TOTAL_COUNT;
        ret = ret?ret:ctcs_qos_query_pool_stats(g_api_lchip, &stats);
        ctc_cli_out("%-5s : %5u\n", "Total", stats.count);
    }

    index = CTC_CLI_GET_ARGC_INDEX("queue-count");
    if (0xFF != index)
    {
        _ctc_cli_asw_qos_queue_id_parser(vty, &stats.queue, &argv[0], argc);

        stats.type = CTC_QOS_RESRC_STATS_QUEUE_COUNT;
        ret = ctcs_qos_query_pool_stats(g_api_lchip, &stats);
        if (ret < 0)
        {
            ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
            return CLI_ERROR;
        }
        ctc_cli_out("%-15s   :  %u\n", "queue-count", stats.count);
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_set_cpu_reason_map,
        ctc_cli_asw_qos_set_cpu_reason_map_cmd,
        "qos (cpu-reason REASON) map-to (queue-id QUEUE)",
        CTC_CLI_QOS_STR,
        "Cpu Reason Id",
        "<0-MAX> refer to cli show qos cpu-reason>",
        "Mapping to",
        "Queue id",
        "<0-7>")
{
    int32 ret = CLI_SUCCESS;
    uint16 reason_id = 0;
    uint16 queue_id = 0;
    uint16 index = 0;

    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    /* Get Cpu Reason Id */
    index = CTC_CLI_GET_ARGC_INDEX("cpu-reason");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("cpu-reason", reason_id, argv[index + 1]);
    }

    /* Get Queue Id */
    index = CTC_CLI_GET_ARGC_INDEX("queue-id");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("queue-id", queue_id, argv[index + 1]);
    }

    que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_MAP;
    que_cfg.value.reason_map.cpu_reason = reason_id;
    que_cfg.value.reason_map.queue_id = queue_id;

    ret = ctcs_qos_set_queue(g_api_lchip, &que_cfg);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_set_queue_pri_map,
        ctc_cli_asw_qos_set_queue_pri_map_cmd,
        "qos queue (priority-mapping PRIORITY) to (qsel QSEL)",
        CTC_CLI_QOS_STR,
        "QoS Queue",
        "Priority Mapping",
        CTC_CLI_PRIORITY_VALUE,
        "To",
        "Queue select",
        CTC_CLI_QOS_QUEUE_VAL)
{
    int32 ret = CLI_SUCCESS;
    uint16 index = 0;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    que_cfg.type = CTC_QOS_QUEUE_CFG_PRI_MAP;

    index = CTC_CLI_GET_ARGC_INDEX("priority-mapping");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("priority", que_cfg.value.pri_map.priority, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("qsel");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("qsel", que_cfg.value.pri_map.queue_select, argv[index + 1]);
    }

    ret = ctcs_qos_set_queue(g_api_lchip, &que_cfg);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_set_cpu_reason_dest,
        ctc_cli_asw_qos_set_cpu_reason_dest_cmd,
        "qos cpu-reason REASON dest-to (eth-cpu  | local-port GPORT | drop )",
        CTC_CLI_QOS_STR,
        "Cpu Reason Id",
        "<0-MAX> refer to cli [show qos cpu-reason]",
        "Destination",
        "Local CPU by network port",
        "Local port",
        CTC_CLI_GPHYPORT_ID_DESC,
        "Drop")
{
    int32 ret = CLI_SUCCESS;
    uint16 reason_id = 0;
    uint8 index = 0;
    uint8 dest_type = 0;
    uint32 dest_port = 0;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    /* Get Cpu Reason Id */
    CTC_CLI_GET_UINT16("cpu-reason", reason_id, argv[0]);

    index = CTC_CLI_GET_ARGC_INDEX("eth-cpu");
    if (0xFF != index)
    {
        dest_type = CTC_PKT_CPU_REASON_TO_LOCAL_CPU_ETH;
    }

    index = CTC_CLI_GET_ARGC_INDEX("local-port");
    if (0xFF != index)
    {
        dest_type = CTC_PKT_CPU_REASON_TO_LOCAL_PORT;
        CTC_CLI_GET_UINT32("gport", dest_port, argv[index + 1]);
    }

    index = CTC_CLI_GET_ARGC_INDEX("drop");
    if (0xFF != index)
    {
        dest_type = CTC_PKT_CPU_REASON_TO_DROP;
    }

    que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_DEST;
    que_cfg.value.reason_dest.cpu_reason = reason_id;
    que_cfg.value.reason_dest.dest_port = dest_port;
    que_cfg.value.reason_dest.dest_type = dest_type;

    ret = ctcs_qos_set_queue(g_api_lchip, &que_cfg);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_get_queue_pri_map,
        ctc_cli_asw_qos_get_queue_pri_map_cmd,
        "show qos queue (priority-mapping PRIORITY)",
        "Show",
        CTC_CLI_QOS_STR,
        "QoS Queue",
        "Priority Mapping",
        CTC_CLI_PRIORITY_VALUE)
{
    int32 ret = CLI_SUCCESS;
    uint16 index = 0;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));

    que_cfg.type = CTC_QOS_QUEUE_CFG_PRI_MAP;
    index = CTC_CLI_GET_ARGC_INDEX("priority-mapping");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT8("priority", que_cfg.value.pri_map.priority, argv[index + 1]);
    }

    ret = ctcs_qos_get_queue(g_api_lchip, &que_cfg);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }
    ctc_cli_out("Queue-select   :%d\n",que_cfg.value.pri_map.queue_select);
    return CLI_SUCCESS;
}

CTC_CLI(ctc_cli_asw_qos_get_cpu_reason,
        ctc_cli_asw_qos_get_cpu_reason_cmd,
        "show qos (cpu-reason REASON) (map-to-queue-info | dest-info)",
        "Show",
        CTC_CLI_QOS_STR,
        "Cpu Reason Id",
        "<0-MAX> refer to cli show qos cpu-reason>",
        "Mapping to queue info",
        "Dest info")
{
    int32 ret = CLI_SUCCESS;
    uint16 cpu_reason = 0;
    uint8 type = 0;
    uint16 index = 0;
    ctc_qos_queue_cfg_t que_cfg;

    sal_memset(&que_cfg, 0, sizeof(ctc_qos_queue_cfg_t));
    /* Get Cpu Reason Id */
    index = CTC_CLI_GET_ARGC_INDEX("cpu-reason");
    if (0xFF != index)
    {
        CTC_CLI_GET_UINT16("cpu-reason", cpu_reason, argv[index + 1]);
    }
    index = CTC_CLI_GET_ARGC_INDEX("map-to-queue-info");
    if (0xFF != index)
    {
        type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_MAP;
        que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_MAP;
        que_cfg.value.reason_map.cpu_reason = cpu_reason;
    }
    else
    {
        type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_DEST;
        que_cfg.type = CTC_QOS_QUEUE_CFG_QUEUE_REASON_DEST;
        que_cfg.value.reason_dest.cpu_reason = cpu_reason;
    }

    ret = ctcs_qos_get_queue(g_api_lchip, &que_cfg);

    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    if(type == CTC_QOS_QUEUE_CFG_QUEUE_REASON_MAP)
    {
        ctc_cli_out("Cpu-reason      : %d\n", que_cfg.value.reason_map.cpu_reason);
        ctc_cli_out("Queue-id        : %d\n", que_cfg.value.reason_map.queue_id);
    }
    else
    {
        ctc_cli_out("Cpu-reason      : %d\n", que_cfg.value.reason_dest.cpu_reason);
        if(que_cfg.value.reason_dest.dest_type == CTC_PKT_CPU_REASON_TO_LOCAL_PORT)
        {
            ctc_cli_out("Dest-type       : %s\n", "local-port");
            ctc_cli_out("Port            : 0x%x\n", que_cfg.value.reason_dest.dest_port);
        }
        else if (que_cfg.value.reason_dest.dest_type == CTC_PKT_CPU_REASON_TO_DROP)
        {
            ctc_cli_out("Dest-type       : %s\n", "drop");
        }
        else if (que_cfg.value.reason_dest.dest_type == CTC_PKT_CPU_REASON_TO_LOCAL_CPU_ETH)
        {
            ctc_cli_out("Dest-type       : %s\n", "local-cpu-eth");
        }
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_show_policer_stats,
        ctc_cli_asw_qos_show_policer_stats_cmd,
        "show qos policer stats (port GPORT  |flow POLICER_ID)",
        CTC_CLI_SHOW_STR,
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Statistics",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        CTC_CLI_QOS_FLOW_PLC_STR,
        CTC_CLI_QOS_FLOW_PLC_VAL)
{
    ctc_qos_policer_stats_t stats_param;
    char   stats_pkts[UINT64_STR_LEN], stats_bytes[UINT64_STR_LEN];
    int32 ret = CLI_SUCCESS;
    int16 idx = 0;
    uint32 gport = 0;

    sal_memset(&stats_param, 0, sizeof(ctc_qos_policer_stats_t));

    /* port policer */
    idx = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("port", gport, argv[idx + 1]);
        stats_param.id.gport = gport;
        stats_param.type = CTC_QOS_POLICER_TYPE_PORT;
    }

    /* flow policer */
    idx = CTC_CLI_GET_ARGC_INDEX("flow");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("policer id", stats_param.id.policer_id, argv[idx + 1]);
        stats_param.type = CTC_QOS_POLICER_TYPE_FLOW;
    }

    ret = ctcs_qos_query_policer_stats(g_api_lchip, &stats_param);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    ctc_cli_out("policer id = %u\n", stats_param.id.policer_id);
    ctc_cli_out("===========================\n");
    ctc_uint64_to_str(stats_param.stats.confirm_pkts, stats_pkts);
    ctc_uint64_to_str(stats_param.stats.confirm_bytes, stats_bytes);
    ctc_cli_out("confirm stats, packet = %s, bytes = %s\n", stats_pkts, stats_bytes);
    ctc_uint64_to_str(stats_param.stats.exceed_pkts, stats_pkts);
    ctc_cli_out("exceed stats, packet = %s\n", stats_pkts);
    ctc_uint64_to_str(stats_param.stats.violate_pkts, stats_pkts);
    ctc_cli_out("violate stats, packet = %s\n", stats_pkts);

    return ret;
}

CTC_CLI(ctc_cli_asw_qos_clear_policer_stats,
        ctc_cli_asw_qos_clear_policer_stats_cmd,
        "clear qos policer stats (port GPORT |flow POLICER_ID )",
        CTC_CLI_CLEAR_STR,
        CTC_CLI_QOS_STR,
        CTC_CLI_QOS_PLC_STR,
        "Statistics",
        CTC_CLI_GPORT_DESC,
        CTC_CLI_GPHYPORT_ID_DESC,
        CTC_CLI_QOS_FLOW_PLC_STR,
        CTC_CLI_QOS_FLOW_PLC_VAL)
{
    ctc_qos_policer_stats_t stats_param;
    int32 ret = CLI_SUCCESS;
    int16 idx = 0;
    uint32 gport = 0;
    sal_memset(&stats_param, 0, sizeof(ctc_qos_policer_stats_t));

    /* port policer */
    idx = CTC_CLI_GET_ARGC_INDEX("port");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("port", gport, argv[idx + 1]);
        stats_param.id.gport = gport;
        stats_param.type = CTC_QOS_POLICER_TYPE_PORT;
    }

    /* flow policer */
    idx = CTC_CLI_GET_ARGC_INDEX("flow");
    if (0xFF != idx)
    {
        CTC_CLI_GET_UINT32("policer id", stats_param.id.policer_id, argv[idx + 1]);
        stats_param.type = CTC_QOS_POLICER_TYPE_FLOW;
    }

    ret = ctcs_qos_clear_policer_stats(g_api_lchip, &stats_param);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s\n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}

CTC_CLI(ctc_cli_asw_show_qos_monitor_glb_pool_state,
        ctc_cli_asw_show_qos_monitor_glb_pool_state_cmd,
        "show qos monitor global pool state",
        CTC_CLI_SHOW_STR,
        "Qos",
        "Monitor",
        "Global",
        "Pool",
        "State")
{
    int32 ret = CLI_SUCCESS;
    uint8 lchip = g_api_lchip;
    ret = ctc_cli_asw_qos_get_monitor_glb_pool_state(vty, lchip);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;

}

CTC_CLI(cli_asw_show_monitor_port_state,
    cli_asw_show_monitor_port_state_cmd,
    "show qos monitor port GPORT state",
    "Show",
    "Show qos info",
    "monitor",
    "Gport",
    "Gport Value",
    "State")
{
    uint32 gport = 0;
    uint8 lchip = g_api_lchip;
    int32 ret = CLI_SUCCESS;
    
    CTC_CLI_GET_INTEGER("gport", gport, argv[0]);
     
    ret = ctc_cli_asw_qos_get_monitor_port_state(vty, lchip, gport);
    if (ret < 0)
    {
        ctc_cli_out("%% ret = %d, %s \n", ret, ctc_get_error_desc(ret));
        return CLI_ERROR;
    }

    return ret;
}


int32
ctc_asw_qos_cli_init(uint8 cli_tree_mode)
{
    /*policer cli*/
    install_element(cli_tree_mode, &ctc_cli_asw_qos_create_policer_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_remove_policer_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_show_policer_cmd);
    /*domain mapping*/
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_igs_domain_map_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_egs_domain_map_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_show_qos_domain_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_ipgEn_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_get_ipgEn_cmd);
    /*drop*/
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_resrc_flow_ctl_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_get_resrc_flow_ctl_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_resrc_ingress_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_resrc_egress_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_get_resrc_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_port_queue_shape_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_port_shape_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_show_shape_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_port_queue_class_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_show_sched_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_queue_wdrr_weight_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_show_resrc_usage_cmd);
    /*cpu reason*/
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_cpu_reason_map_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_queue_pri_map_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_get_queue_pri_map_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_get_cpu_reason_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_set_cpu_reason_dest_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_show_policer_stats_cmd);
    install_element(cli_tree_mode, &ctc_cli_asw_qos_clear_policer_stats_cmd);
    /*debug show*/
    install_element(cli_tree_mode, &ctc_cli_asw_show_qos_monitor_glb_pool_state_cmd);
    install_element(cli_tree_mode, &cli_asw_show_monitor_port_state_cmd);

    return CLI_SUCCESS;
}
